package com.mujin.keji.collectionsystem.module.outboundtask.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.listeners.CustomItemClickListener;
import com.mujin.keji.collectionsystem.listeners.FunctionItemClickListener;
import com.mujin.keji.collectionsystem.module.main.dto.FunctionDto;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.StatusCountDto;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.TripStatusDto;
import com.mujin.keji.collectionsystem.utils.EmptyUtils;

import java.util.List;


/**
 * 外访状态适配器
 *
 * @author weishixiong
 * @Time 2018-03-21
 */

public class TripStatusAdapter extends RecyclerView.Adapter<TripStatusAdapter.ViewHolder> {

    private Activity mContext;
    private List<StatusCountDto> datas;
    private CustomItemClickListener listener;
    private String colors[] = new String[]{"#141414", "#888888"};

    public TripStatusAdapter(Activity context, List<StatusCountDto> datas, CustomItemClickListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_trip_status, null, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {


        if (EmptyUtils.isNotEmpty(datas.get(position).getStatus())) {
            if (datas.get(position).getStatus() == 1) {
                holder.tv_status.setText("待外访");
            } else if (datas.get(position).getStatus() == 2) {
                holder.tv_status.setText("已外访");
            } else if (datas.get(position).getStatus() == 3) {
                holder.tv_status.setText("已完成");
            }
        }
        holder.tv_count.setText(datas.get(position).getCount() + "");
        if (position > 0) {
            holder.v_line.setVisibility(View.VISIBLE);
        } else {
            holder.v_line.setVisibility(View.GONE);
        }
        holder.ll_status.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onItemClick(null, position);
            }
        });
        if (datas.get(position).isSelected()) {
            holder.tvLine.setVisibility(View.VISIBLE);
        } else {
            holder.tvLine.setVisibility(View.GONE);

        }

    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        public TextView tv_status;
        public TextView tv_count;
        public View v_line;
        public LinearLayout ll_status;
        private TextView tvLine;


        public ViewHolder(View itemView) {
            super(itemView);
            tv_status = (TextView) itemView.findViewById(R.id.tv_status);
            tv_count = (TextView) itemView.findViewById(R.id.tv_count);
            v_line = itemView.findViewById(R.id.v_line);
            tvLine = (TextView) itemView.findViewById(R.id.tv_line);
            ll_status = (LinearLayout) itemView.findViewById(R.id.ll_status);
        }

    }
}
